home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_11 / phillip2 / main2seg.c < prev    next >
Text File  |  1993-06-10  |  5KB  |  166 lines

  1.  
  2.        /***********************************************
  3.        *
  4.        *       file d:\cips\main2seg.c
  5.        *
  6.        *       Functions: This file contains
  7.        *          main
  8.        *
  9.        *       Purpose:
  10.        *          This is a calling program that calls
  11.        *          the three new segmentation techniques
  12.        *          discussed in Image Processing part 10.
  13.        *
  14.        *       External Calls:
  15.        *          gin.c - get_image_name
  16.        *          numcvrt.c - get_integer
  17.        *                      int_convert
  18.        *          tiff.c - read_tiff_header
  19.        *          segment2.c - edge_region
  20.        *                       gray_shade_region
  21.        *                       edge_gray_shade_region
  22.        *
  23.        *       Modifications:
  24.        *          5 December 1992 - created
  25.        *
  26.        ***********************************************/
  27.  
  28. #include "cips.h"
  29.  
  30.  
  31.  
  32. short the_image[ROWS][COLS];
  33. short out_image[ROWS][COLS];
  34.  
  35. main(argc, argv)
  36.    int argc;
  37.    char *argv[];
  38. {
  39.  
  40.    char     name[80], name2[80], low_high[80], type[80];
  41.    float    percent;
  42.    int      count, i, ie, il, j, le, length, ll,
  43.             looking = 1, lw, width;
  44.    short    value,  value2, value3, 
  45.             value4, value5, value6;
  46.    struct   tiff_header_struct image_header;
  47.    my_clear_text_screen();
  48.  
  49.        /***********************************************
  50.        *
  51.        *       Interpret the command line parameters.
  52.        *
  53.        ************************************************/
  54.  
  55.    if(argc < 4){
  56.     printf(
  57.     "\n\nNot enough parameters:"
  58.      "\n"
  59.      "\n usage: main2seg in-file out-file type"
  60.      " [values ...]"
  61.      "\n"
  62.      "\n   recall type: Edge-region edge-gray-grow (C)"
  63.      " Gray-shade-grow"
  64.      "\n"
  65.     "\n   main2seg in-file out-file C percent "
  66.     "edge-type "
  67.     "\n            min-area max-area diff set-value erode"
  68.     "\n   main2seg in-file out-file E percent "
  69.     "edge-type "
  70.     "\n            min-area max-area diff set-value erode"
  71.     "\n   main2seg in-file out-file G diff "
  72.     "min-area max-area"
  73.     "\n"
  74.     "\n");
  75.     exit(0);
  76.    }
  77.  
  78.    strcpy(name,  argv[1]);
  79.    strcpy(name2, argv[2]);
  80.    strcpy(type,  argv[3]);
  81.    if(type[0] == 'a' || type[0] == 'A'  ||
  82.       type[0] == 'c' || type[0] == 'C'  ||
  83.       type[0] == 'e' || type[0] == 'E'){
  84.       percent = atof(argv[4]);
  85.       value   = atoi(argv[5]);
  86.       value2  = atoi(argv[6]);
  87.       value3  = atoi(argv[7]);
  88.       value4  = atoi(argv[8]);
  89.       value5  = atoi(argv[9]);
  90.       value6  = atoi(argv[10]);
  91.     }
  92.    else{
  93.       value  = atoi(argv[4]);
  94.       value2 = atoi(argv[5]);
  95.       value3 = atoi(argv[6]);
  96.    }
  97.  
  98.    il = 1;
  99.    ie = 1;
  100.    ll = ROWS+1;
  101.    le = COLS+1;
  102.  
  103.        /******************************************
  104.        *
  105.        *  Read the input image header and setup
  106.        *  the looping counters.
  107.        *
  108.        *******************************************/
  109.  
  110.    read_tiff_header(name, &image_header);
  111.  
  112.    length = (ROWS-10 + image_header.image_length)/ROWS;
  113.    width  = (COLS-10 + image_header.image_width)/COLS;
  114.    count  = 1;
  115.    lw     = length*width;
  116.    printf("\nlength=%d  width=%d", length, width);
  117.  
  118.  
  119.    if(type[0] == 'e'  || type[0] == 'E'){
  120.       for(i=0; i<length; i++){
  121.          for(j=0; j<width; j++){
  122.             printf("\nrunning %d of %d", count, lw);
  123.             count++;
  124.             edge_region(name, name2, the_image, 
  125.                         out_image, il+i*ROWS, 
  126.                         ie+j*COLS, ll+i*ROWS,
  127.                         le+j*COLS, value, value2, 
  128.                         value3, value4, percent, 
  129.                         value5, value6);
  130.          }  /* ends loop over j */
  131.       }  /* ends loop over i */
  132.    }  /* ends edge_region */
  133.  
  134.  
  135.  
  136.    if(type[0] == 'g'  || type[0] == 'G'){
  137.       for(i=0; i<length; i++){
  138.          for(j=0; j<width; j++){
  139.             printf("\nrunning %d of %d", count, lw);
  140.             count++;
  141.             gray_shade_region(name, name2, the_image,
  142.                               out_image, il+i*ROWS,
  143.                               ie+j*COLS, ll+i*ROWS,
  144.                               le+j*COLS, value,
  145.                               value2, value3);
  146.          }  /* ends loop over j */
  147.       }  /* ends loop over i */
  148.    }  /* ends gray_shade_region */
  149.  
  150.  
  151.  
  152.    if(type[0] == 'c'  || type[0] == 'C'){
  153.       for(i=0; i<length; i++){
  154.          for(j=0; j<width; j++){
  155.             printf("\nrunning %d of %d", count, lw);
  156.             count++;
  157.             edge_gray_shade_region(name, name2, 
  158.                      the_image, out_image, il+i*ROWS, 
  159.                      ie+j*COLS, ll+i*ROWS, le+j*COLS,
  160.                      value, value2, value3, value4, 
  161.                      percent, value5, value6);
  162.          }  /* ends loop over j */
  163.       }  /* ends loop over i */
  164.    }  /* ends edge_gray_shade_region */
  165.  
  166. }  /* ends main  */